extends Area2D


var shortpressed = false
var longpressed = false

@onready var collision_shape = $CollisionShape2D

func set_rect(rect: Vector2):
	var rectangle: RectangleShape2D = collision_shape.shape
	rectangle.size = rect
	position = Vector2(rect.x / 2, rect.y / 2)

func _on_input_event(viewport, event, shape_idx):
	print('1')
	if event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_LEFT and event.pressed:
		$Timer.start()
		shortpressed = true
		longpressed = true
	if event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_LEFT and not event.pressed:
		if $Timer.time_left > 0:
			$Timer.stop()
			longpressed = false
			print("识别为短按"," long:",longpressed," short:",shortpressed)
	#Godot 原版自带的双击识别，和本代码有一定的逻辑重复
	if event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_LEFT and event.doubleclick:
		print("识别为双击")


func _on_timer_timeout():
	print('2')
	if longpressed:
		shortpressed = false
		print("识别为长按"," long:",longpressed," short:",shortpressed)
